var e = require("../../../@babel/runtime/helpers/interopRequireDefault")(require("../../../dist/dialog/dialog")), t = getApp();

Page({
    data: {
        orderId: null,
        type: null,
        orderType: null,
        refundDetails: {},
        orderDetails: {},
        receivingStatus: "not_received",
        refundTypes: [],
        reasons: [ "买多了/买错了", "计划有变，暂时不需要了", "不能送外卖", "使用条件不清楚", "联系不上商家", "约不到合适的时间", "可用的门店距离太远", "其他平台/方式购买更优惠", "评价不好", "担心安全问题（疫情、天气等）" ],
        refundValue: "",
        refundRadio: "",
        explain: "",
        refundSum: 1,
        refundShow: !1
    },
    onLoad: function(e) {
        var t;
        "" !== (null !== (t = e.orderId) && void 0 !== t ? t : "") && (this.setData({
            orderId: Number(e.orderId),
            type: e.type,
            orderType: e.orderType
        }), this.goodsRefund());
    },
    onRefund: function() {
        var n = this;
        t._isTextEmpty(this.data.refundValue) ? wx.showToast({
            icon: "none",
            title: "请选择退款原因",
            duration: 1500
        }) : e.default.confirm({
            message: "退款申请一旦提交，将不能撤销，是否确认继续退款？"
        }).then(function() {
            var e = t.getNetAddresss("refund.apply.store"), o = {
                content: n.data.explain,
                freight_price: 0,
                order_id: n.data.orderId,
                other_price: 0,
                part_refund: 1,
                reason: n.data.refundValue,
                receive_status: 0,
                refund_id: n.data.orderId,
                refund_type: 0,
                refund_way_type: 0
            };
            t._postNetWork({
                url: e,
                data: o,
                success: function(e) {
                    var t = e.data;
                    if (1 == t.result) {
                        wx.showToast({
                            icon: "none",
                            title: t.msg,
                            duration: 1500
                        });
                        var o = getCurrentPages();
                        o[o.length - 2].setData({
                            tabIndex: 4
                        }), n.data.orderType ? setTimeout(function() {
                            wx.navigateBack({
                                delta: 2
                            });
                        }, 1e3) : setTimeout(function() {
                            wx.navigateBack({
                                delta: 1
                            });
                        }, 1e3);
                    } else wx.showToast({
                        icon: "none",
                        title: t.msg,
                        duration: 1500
                    });
                },
                fail: function(e) {
                    console.log(e);
                }
            });
        }).catch(function() {});
    },
    goodsRefund: function() {
        var e = this, n = t.getNetAddresss("refund.apply"), o = {
            order_id: this.data.orderId,
            type: this.data.type
        };
        t._getNetWork({
            url: n,
            data: o,
            success: function(t) {
                var n = t.data;
                1 == n.result ? e.setData({
                    orderDetails: n.data.order,
                    refundSum: n.data.order.order_goods[0].total
                }) : wx.showToast({
                    icon: "none",
                    title: n.msg,
                    duration: 1500
                });
            },
            fail: function(e) {
                console.log(e);
            }
        });
    },
    onrefundChange: function(e) {
        this.setData({
            refundRadio: e.detail
        });
    },
    onTotalChange: function(e) {
        this.setData({
            refundSum: e.detail
        });
    },
    explainInput: function(e) {
        this.setData({
            explain: e.detail.value
        });
    },
    refundBtn: function() {
        this.setData({
            refundValue: this.data.refundRadio,
            refundShow: !1
        });
    },
    getMiniTemplateCorrespond: function() {
        var e = t.getNetAddresss("member.member.getMiniTemplateCorrespond"), n = {
            type: this.data.type = 2
        };
        t._getNetWork({
            url: e,
            data: n,
            success: function(e) {
                var t = e.data;
                1 == t.result ? console.log(t) : wx.showToast({
                    icon: "none",
                    title: t.msg,
                    duration: 1500
                });
            },
            fail: function(e) {
                console.log(e);
            }
        });
    },
    onClose: function() {
        this.setData({
            refundShow: !1
        });
    },
    onCause: function() {
        this.setData({
            refundShow: !0
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {}
});